#!/usr/bin/python
# -*- coding:UTF-8 -*-
# @Time    : 2019/1/11 8:15
# @Author  : 王志鹏
# @Site    : 冒泡排序 稳定
# @File    : temp.py
# @Software: PyCharm
import sys
import json


class Algorithm(object):
    def __init__(self):
        pass

    def demo2(self):
        # 字典列表
        demoList = [{"小明": 12},
                    {"小黑": 35},
                    {"小红": 99},
                    {"小绿": 18},
                    {"小刚": 76}]

        demoListLength = len(demoList)
        for i in range(demoListLength):
            for j in range(demoListLength - (i + 1)):
                now = demoList[j]
                if now.values() < demoList[j + 1].values():
                    demoList[j] = demoList[j + 1]
                    demoList[j + 1] = now

        print json.dumps(demoList, encoding='utf-8', ensure_ascii=False)

    def main(self):
        # 时间杂度 O(N^2)
        demoList = [12, 35, 99, 18, 76]
        demoListLength = len(demoList)
        # 大>小
        print demoList, "demoList"
        for i in range(demoListLength):
            for j in range(demoListLength - (i + 1)):
                now = demoList[j]
                if now < demoList[j + 1]:
                    demoList[j] = demoList[j + 1]
                    demoList[j + 1] = now
                print demoList
            print
        print "下面为最终结果"

        print demoList

        self.demo2()


if __name__ == '__main__':
    algorithm = Algorithm()
    algorithm.main()
